@extends('admin.base')
@section('title', '商品列表')
@section('content')
    <div class="layui-card">
        <fieldset class="layui-elem-field">
            <div class="layui-field-box">
                    <span class="layui-breadcrumb">
                      <a href="/admin/home">首页</a>
                      <a href="/admin/shop/index?page=@if($request->page){{$request->page}}@else 1 @endif&keywords={{$request->keywords}}&label={{$request->label}}&type={{$request->type}}&brand={{$request->brand}}&state={{$request->state}}&sell={{$request->sell}}&month={{$request->month}}&title={{$request->title}}&sort={{$request->sort}}">商品列表</a>
                      <a href="">{{$gname}} - 问答库</a>
                    </span>
            </div>
        </fieldset>

        {{--<blockquote class="layui-elem-quote layui-quote-nm">--}}
            {{--{{$gname}} 包含的问答库--}}
        {{--</blockquote>--}}
        <div class="layui-card-body">
            @if(count($data)>0)
                <form class="layui-form layui-form-pane" method="post" action="{{url('admin/shop/qanda_update')}}" >
                    @csrf
                    <input type="hidden" name="gid" value="{{$id}}" >

                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">问题</label>
                        <div class="layui-input-inline" style="width: auto;">
                            @foreach($data as $v)
                                <input type="checkbox" name="qid[]" value="{{$v['id']}}" title="{{$v['question']}}" lay-skin="primary" checked>
                            @endforeach
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="formDemo_up">修改</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
            @else
                暂未选择规格
            @endif
        </div>

        <blockquote class="layui-elem-quote layui-quote-nm">
            未包含的规格
        </blockquote>
        <div class="layui-card-body">
            <form class="layui-form" method="post" action="" >
                @csrf
                <input type="hidden" name="gid" value="{{$id}}" >
                <div class="layui-form-item" >
                    <label class="layui-form-label" style="width:auto;text-align: center;" >
                        <select name="qid" lay-filter="kids" lay-verify="" lay-search >
                            <option value="0">==请选择==</option>
                            @foreach($res as $v)
                                <option value="{{$v->id}}">{{$v->question}}</option>
                            @endforeach
                        </select>
                    </label>
                    <div class="layui-input-inline layui-form" lay-filter="test2" id="valueslist" style="width: auto;">

                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </form>
        </div>
    </div>
@endsection
@section('js')
    <script type="text/javascript">
        layui.use('form', function(){
            let form = layui.form;
            form.render();
            //监听提交
            //修改
            form.on('submit(formDemo_up)', function(data){
                layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                    ajax("{{url('admin/shop/qanda_update')}}",data.field, function(data){
                        layer.close();
                        layer.closeAll();
                        layer.msg(data.msg);
                        if(data.code == 1){
                            window.location.reload();
                        }
                    });
                });
                return false;
            });

            //添加
            form.on('submit(formDemo)', function(data){
                layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                    ajax("{{url('admin/shop/qanda_insert')}}",data.field, function(data){
                        layer.close();
                        layer.closeAll();
                        layer.msg(data.msg);
                        if(data.code == 1){
                            window.location.reload();
                        }
                    });
                });
                return false;
            });
        });

    </script>
@endsection